Component({
  attached() {
    //被添加事件
    wx.setNavigationBarTitle({
      title: this.data.tabs[this.properties.active].title,
    });
  },
  options: {
    addGlobalClass: true,
  },
  properties:{
    //效果类似于data，更倾向于外界传输数据给组件
    active: {
      type:Number,
      value:0
    },
  },
  data: {
    tabs: [
      {name:'首页',title:'首页',icon:'home-o',path:'/pages/home/index'},
      {name:'分类',title:'分类',icon:'apps-o',path:'/pages/category/index'},
      {name:'购物车',title:'购物车',icon:'cart-o',path:'/pages/cart/index'},
      {name:'我的',title:'个人中心',icon:'user-o',path:'/pages/usercenter/index'}
    ],
    activeColor: '#666',
  },
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      wx.reLaunch({url: this.data.tabs[event.detail].path});
      //wx.switchTab({url: urls[event.detail]});
      //this.setData({ active: event.detail});
      wx.setNavigationBarTitle({
        title: this.data.tabs[event.detail].title,
      });
    },
  }
});